<template>
  <div class="reservationRecord">
    <div class="header">
      <van-nav-bar title="我的记录" fixed left-text="返回" right-text left-arrow @click-left="onClickLeft"/>
    </div>
    <div class="recordDetails_con">
      <div class="list" v-if="recordData.list&&recordData.list.length>0">
      <van-list
        v-model="loading"
        :finished="finished"
        @load="onLoad"
        :offset="100"
        finished-text="没有更多了"
      >
        <ul>
          <li v-for="(item,index) in recordData.list"  :key="index">
            <div class="recordDetails_con_head" @click="link(item)">
              <img :src="item.shop_image_url"/>
              <p class="recordDetails_con_head_span">{{item.shopName}}</p>
              <div>
                <van-icon name="arrow" />
              </div>
            </div>
            <div class="recordDetails_con_con">
              <div class="recordDetails_con_con_img">
                <img :src="item.product_image_url"/>
              </div>

              <div class="recordDetails_con_con_title">
                <p>{{item.productName}}</p>
                <span>￥{{item.price}}</span>
                <span>x{{item.quantity}}</span>
              </div>
            </div>
            <div class="recordDetails_con_foot">
              <p>订单状态：
                <span v-if="item.payment_state==0">支付失败</span>
                <span v-if="item.payment_state==1">支付成功</span>
                <span v-if="item.payment_state==2">待支付</span>
                <span v-if="item.payment_state==100">已支付(待确认)</span>
                <span v-if="item.payment_state==101">已失效</span>
                <span v-if="item.payment_state==102">已取消</span>
              </p>
              <p>订单号码：<span>{{item.serial_number}}</span></p>
              <p>付款时间：<span>{{item.pay_time}}</span></p>
              <p>联系电话：<span>{{item.consigneePhone}}</span></p>
            </div>
          </li>
        </ul>
      </van-list>
      </div>
      <div class="empty" v-else>暂无数据</div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "travelRecord",
    data() {
      return {
        recordData:[],
        recordDataList:[],
        //下拉刷新
        isLoading: false,
        //上拉加载
        loading: false,
        finished: false,
        pageNum: 1,
      };
    },
    mounted() {
      this.getReservationRecordData()
    },
    methods: {
      //  返回上一层
      onClickLeft() {
        this.$router.back();
      },
      //跳回景点详情页面
      link(item){
        this.$router.push({path: "./travelDetails", query: {shopId: item.shop_id}});
      },
      //获取预订记录信息
      async getReservationRecordData() {
        let params = {
          pageNum: this.pageNum,
          pageSize:10,
        };
        const res = await this.$axios.post(this.$api.travelRecordData, params);
        if (res.success) {
          if (this.loading) {
            this.recordDataList = this.recordDataList.concat(res.data.list);
            this.recordData = res.data;
            this.recordData.list = this.recordDataList;
            if (this.recordData.list.length >= this.recordData.total) {
              this.finished = true;
            } else {
              this.pageNum++;
            }
          } else {
            this.recordData = res.data;
            if (this.recordData.list.length >= this.recordData.total) {
              this.finished = true;
            }
          }
          this.isLoading = false;
          this.loading = false;
        } else {
          this.$toast(res.msg);
        }
      },
      //下拉刷新
      onRefresh() {
        this.getReservationRecordData()
      },
      //上拉加载
      onLoad() {
        if (this.recordData.list && this.recordData.list.length > 0) {
          this.getReservationRecordData();
        }
      },
    }
  }
</script>

<style scoped>
  .header{width: 100%;}
  .recordDetails_con{width: 100%;margin-top: 0.57rem;}
  .recordDetails_con ul li{margin:0.16rem;background-color: #fff;border-radius: 0.1rem; }
  .recordDetails_con_head{line-height: 0.47rem;overflow: hidden;border-bottom: 1px solid #f7f7f7;width: 90%;margin: 0 auto;}
  .recordDetails_con_head img{float: left;margin-top:0.11rem;width: 0.25rem;height: 0.25rem;margin-right: 0.13rem;border-radius: 1rem;}
  .recordDetails_con_head_span{color: #000;width: 75%;float: left;font-size: 0.14rem;}
  .recordDetails_con_head div{float: right;width: 10%;}
  .recordDetails_con_head div i{font-size: 0.16rem;padding: 0.155rem 0;float: right;}
  .recordDetails_con_con{overflow: hidden;border-bottom: 1px solid #f7f7f7;width: 90%;margin: 0 auto;}
  .recordDetails_con_con_img{float: left;margin-top:0.1rem;width: 25.45%;height: 0.7rem;margin-right: 0.15rem;}
  .recordDetails_con_con_img img{border-radius: 0.1rem;width: 100%;height: 100%;}
  .recordDetails_con_con_title{float: left;width: 68%;padding: 0.24rem 0 0.2rem;}
  .recordDetails_con_con_title p{font-size: 0.15rem;color: #000;padding-bottom: 0.1rem;}
  .recordDetails_con_con_title span:nth-child(2){color: #ff202f;font-size: 0.11rem;}
  .recordDetails_con_con_title span:nth-child(3){color: #000;font-size: 0.15rem;float: right;}
  .recordDetails_con_foot{width: 90%;margin: 0 auto;padding: 0.15rem 0;}
  .recordDetails_con_foot p{font-size: 0.13rem;color: #808080;line-height: 0.2rem;}
  .recordDetails_con_foot p span{font-size: 0.13rem;color: #000;}
  .empty{
    width:100%;
    margin-top:.4rem;
    text-align: center;
    font-size:.16rem;
    color:#999999;
  }
</style>

